package com.example.q_kang.hhh.view;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomSheetDialog;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.ViewGroup;
import android.widget.RelativeLayout;

import com.bulong.rudeness.RudenessScreenHelper;
import com.example.q_kang.hhh.R;
import com.sskj.base.adapter.slimadapter.IViewInjector;
import com.sskj.base.adapter.slimadapter.SlimAdapter;
import com.sskj.base.adapter.slimadapter.SlimInjector;
import com.sskj.base.view.DividerLineItemDecoration;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class OrderChooseDailog extends BottomSheetDialog {

    @BindView(R.id.rl_close)
    RelativeLayout rl_close;
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;

    private SlimAdapter<String> slimAdapter;
    private Context mContext;

    private SelectListener mListener;

    public OrderChooseDailog(@NonNull Context context) {
        super(context);
        this.mContext = context;
    }

    public OrderChooseDailog(@NonNull Context context, int theme) {
        super(context, theme);
        this.mContext = context;
    }

    protected OrderChooseDailog(@NonNull Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
        this.mContext = context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.select_order_type);
        ButterKnife.bind(this);
        getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

        recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
        recyclerView.addItemDecoration(new DividerLineItemDecoration(mContext)
                .setPaintWidth((int) RudenessScreenHelper.pt2px(mContext, 1))
                .setDividerColor(ContextCompat.getColor(mContext, R.color.divider_s))
                .setFirstDraw(false)
                .setLastDraw(false));
        slimAdapter = SlimAdapter.create().register(R.layout.item_order_choose, new SlimInjector<String>() {
            @Override
            public void onInject(String data, IViewInjector injector) {
                injector.text(R.id.tv_number, data)
                        .clicked(R.id.tv_number, view -> mListener.selectByAlbum(data));
            }
        }).attachTo(recyclerView).updateData(new ArrayList());
        rl_close.setOnClickListener(v -> {
            dismiss();
        });
    }

    public void setData(List<String> data) {
        if (slimAdapter != null) {
            slimAdapter.updateData(data);
        }
    }


    public void setOnSelectListener(SelectListener listener) {
        this.mListener = listener;
    }

    public interface SelectListener {
        void selectByAlbum(String money);
    }

    @Override
    public void show() {
        super.show();

    }
}